package main

import (
	"log"
	"news_for_deepseek_interface/config"
	"news_for_deepseek_interface/logger"
	"news_for_deepseek_interface/middleware"
	"news_for_deepseek_interface/model"
	"news_for_deepseek_interface/project/rabbitmq"
	"news_for_deepseek_interface/router/admin"
	"time"

	"github.com/gin-gonic/gin"
)

func main() {
	// 1. 设置时区
	loc, err := time.LoadLocation("Asia/Shanghai")
	if err != nil {
		log.Fatalf("设置时区失败: %v", err)
	}
	time.Local = loc

	//初始化mysql
	if err := model.Initialize(); err != nil {
		logger.Error("Failed to initialize MySQL: %s", err.Error())
		return
	}

	// 初始化 RabbitMQ
	if err := rabbitmq.InitRabbitMQ(); err != nil {
		logger.Error("Failed to initialize RabbitMQ: %s", err.Error())
		return
	}

	// 5. 初始化 Gin
	r := gin.Default()
	r.Use(middleware.CorsMiddleware())
	r.Static("/uploads", "./uploads")

	// 6. 设置路由
	admin.NoLogin(r)
	admin.StartRoutes(r)

	// 7. 启动服务器
	if err := r.Run(":" + config.DefaultConfig.Server.Port); err != nil {
		log.Fatalf("服务器启动失败: %v", err)
	}
}
